home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / lang / SmallEiffel.lha / SmallEiffel / lib_se / expression.e < prev    next >
Text File  |  1998-12-22  |  10KB  |  412 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. deferred class EXPRESSION
  17.    --
  18.    -- Any kind of Eiffel expression.
  19.    --
  20.    
  21. inherit GLOBALS;
  22.    
  23. feature
  24.  
  25.    is_current: BOOLEAN is
  26.       deferred
  27.       end;
  28.  
  29.    is_manifest_string: BOOLEAN is
  30.       deferred
  31.       end;
  32.  
  33.    is_void: BOOLEAN is
  34.       deferred
  35.       end;
  36.  
  37.    is_result: BOOLEAN is 
  38.       deferred
  39.       end;
  40.  
  41.    is_writable: BOOLEAN is 
  42.       deferred
  43.       end;
  44.       
  45.    result_type: TYPE is
  46.       deferred
  47.       ensure
  48.      Result /= Void
  49.       end;
  50.    
  51.    use_current: BOOLEAN is
  52.       require
  53.      small_eiffel.is_ready
  54.       deferred
  55.       end;
  56.    
  57.    to_runnable(ct: TYPE): like Current is
  58.      -- Gives the corresponding expression checked in `ct'.
  59.       require
  60.      ct.run_type = ct;
  61.      ct.run_class /= Void
  62.       deferred
  63.       ensure
  64.      nb_errors = 0 implies Result.result_type.is_run_type
  65.       end;
  66.  
  67. feature 
  68.  
  69.    isa_dca_inline_argument: INTEGER is
  70.      -- Interpretation of the Result :
  71.      --    -1 : yes and no ARGUMENT_NAME used
  72.      --     0 : not inlinable
  73.          --   > 0 : inlinable and ARGUMENT_NAME rank is used.
  74.       require
  75.      run_control.boost and small_eiffel.is_ready
  76.       deferred
  77.       ensure
  78.      Result >= -1
  79.       end;
  80.  
  81.    dca_inline_argument(formal_arg_type: TYPE) is
  82.       require
  83.      formal_arg_type /= Void;
  84.      isa_dca_inline_argument /= 0
  85.       deferred
  86.       end;
  87.  
  88. feature  -- Handling of precedence (priority of expressions) :
  89.    
  90.    precedence: INTEGER is
  91.       deferred
  92.       ensure
  93.      1 <= Result and Result <= atomic_precedence
  94.       end;
  95.       
  96. feature  
  97.    
  98.    frozen add_comment(c: COMMENT): EXPRESSION is
  99.      -- Attach `c' to the receiver.
  100.       do
  101.      if c = Void or else c.count = 0 then
  102.         Result := Current;
  103.      else
  104.         !EXPRESSION_WITH_COMMENT!Result.make(Current,c);
  105.      end;
  106.       end;
  107.    
  108.    start_position: POSITION is
  109.      -- Of the expression if any.
  110.       deferred
  111.       end;
  112.    
  113.    frozen base_class_written: BASE_CLASS is
  114.       do
  115.      Result := written_in.base_class;
  116.       end;
  117.    
  118.    frozen written_in: CLASS_NAME is
  119.      -- The name of the base class where the expression is 
  120.      -- written if any.
  121.       local
  122.      sp: like start_position;
  123.       do
  124.      sp := start_position;
  125.      if sp /= Void then
  126.         Result := sp.base_class_name;
  127.      end;
  128.       end;
  129.    
  130.    afd_check is
  131.      -- After Falling Down Check.
  132.       deferred
  133.       end;
  134.  
  135. feature -- To produce C code :
  136.  
  137.    collect_c_tmp is
  138.      -- Traverse the expression to collect needed C tmp variables
  139.      -- just before `compile_to_c'.
  140.       require
  141.      small_eiffel.is_ready
  142.       deferred
  143.       end;
  144.  
  145.    compile_to_c is
  146.      -- Produce C code to access the value of the Current 
  147.      -- expression : user's expanded are no longuer pointer.
  148.       require
  149.      small_eiffel.is_ready;
  150.      cpp.on_c
  151.       deferred
  152.       ensure     
  153.      cpp.on_c
  154.       end;
  155.  
  156.    mapping_c_target(formal_type: TYPE) is
  157.      -- Produce C code in order to pass Current expression as 
  158.      -- the target of a feature call.
  159.      -- When it is needed, C code to check invariant is 
  160.      -- automatically added as well as a C cast according to 
  161.      -- the destination `formal_type'.
  162.       require
  163.      small_eiffel.is_ready;
  164.      formal_type.at_run_time
  165.       deferred
  166.       end;
  167.  
  168.    mapping_c_arg(formal_arg_type: TYPE) is
  169.      -- Produce C code in order to pass Current expression as an 
  170.      -- argument of the feature called.
  171.      -- Thus, it is the same jobs as `mapping_c_target' without
  172.      -- the invariant call.
  173.       require
  174.      small_eiffel.is_ready
  175.       deferred
  176.       end;
  177.    
  178.    c_declare_for_old is
  179.      -- Produce C code to declare `old' expression variables.
  180.       require
  181.      small_eiffel.is_ready;
  182.      cpp.on_c
  183.       deferred
  184.       ensure     
  185.      cpp.on_c
  186.       end;
  187.  
  188.    compile_to_c_old is
  189.      -- Produce C code to memorize `old' expression values.
  190.       require
  191.      small_eiffel.is_ready;
  192.      cpp.on_c
  193.       deferred
  194.       ensure     
  195.      cpp.on_c
  196.       end;
  197.  
  198. feature  -- To produce C code :
  199.    
  200.    c_simple: BOOLEAN is
  201.      -- True when the C code of `compile_c' has no side effect at 
  202.      -- and `compile_to_c' on the corresponding simple expression 
  203.      -- can be called more than once without any problem. 
  204.       deferred
  205.       end;
  206.    
  207.    can_be_dropped: BOOLEAN is
  208.      -- True if evaluation of current expression has NO possible 
  209.      -- side effects. Thus, in such a case, an unused expression 
  210.      -- can be dropped (for example target of real procedure or 
  211.      -- real function).
  212.       require
  213.      small_eiffel.is_ready
  214.       deferred
  215.       end;
  216.    
  217. feature  -- Finding `int' Constant C expression :
  218.    
  219.    is_static: BOOLEAN is
  220.      -- True if expression has always the same static
  221.      -- value: INTEGER or BOOLEAN value is always the same 
  222.      -- or when reference is always the same (Void or the 
  223.      -- same manifest string for example).
  224.       require
  225.      small_eiffel.is_ready
  226.       deferred   
  227.       end;
  228.    
  229.    static_value: INTEGER is
  230.       require
  231.      is_static
  232.       deferred
  233.       end;
  234.    
  235.    is_pre_computable: BOOLEAN is
  236.      -- Can the current expression be pre-computed in main 
  237.      -- function to speed up a once function ?
  238.       require
  239.      small_eiffel.is_ready
  240.       deferred
  241.       end;
  242.  
  243. feature -- For `compile_to_jvm' :
  244.    
  245.    compile_to_jvm is
  246.      -- Produce Java byte code in order to push expression value 
  247.      -- on the jvm stack.
  248.       require
  249.      small_eiffel.is_ready
  250.       deferred
  251.       end;
  252.  
  253.    compile_target_to_jvm is
  254.      -- Same as `compile_to_jvm', but add class invariant check
  255.      -- when needed.
  256.       require
  257.      small_eiffel.is_ready
  258.       deferred
  259.       end;
  260.  
  261.    compile_to_jvm_old is
  262.      -- Produce Java byte code to memorize `old' expression values.
  263.       require
  264.      small_eiffel.is_ready
  265.       deferred
  266.       end;
  267.    
  268.    compile_to_jvm_into(dest: TYPE): INTEGER is
  269.      -- Assume `result_type' conforms to `dest'.
  270.      -- Produce Java byte code in order to convert the expression 
  271.      -- into `dest' (comparisons = and /=, argument passing and 
  272.      -- assignment).
  273.      -- Result gives the space in the JVM stack.
  274.       require
  275.      conversion_check(dest,result_type)
  276.       deferred
  277.       ensure
  278.      Result >= 1
  279.       end;
  280.  
  281. feature {NONE}
  282.  
  283.    frozen standard_compile_target_to_jvm is
  284.       do
  285.      compile_to_jvm;
  286.      result_type.jvm_check_class_invariant;
  287.       end;
  288.  
  289.    frozen standard_compile_to_jvm_into(dest: TYPE): INTEGER is
  290.       require
  291.      conversion_check(dest,result_type)
  292.       do
  293.      compile_to_jvm;
  294.      Result := result_type.run_type.jvm_convert_to(dest);
  295.       ensure
  296.      Result >= 1
  297.       end;
  298.  
  299.    conversion_check(dest, rt: TYPE): BOOLEAN is
  300.       do
  301.      Result := true;
  302.      if rt.is_a(dest) then
  303.      else
  304.         eh.cancel;
  305.         if dest.is_a(rt) then
  306.         else
  307.            warning(start_position,
  308.         ". Impossible conversion (EXPRESSION).");
  309.         end;
  310.      end;
  311.       end;
  312.  
  313. feature
  314.  
  315.    compile_to_jvm_assignment(a: ASSIGNMENT) is
  316.      -- Current is the writable which is the left-hand-side
  317.      -- of `a'.
  318.       require
  319.      Current = a.left_side
  320.       deferred
  321.       end;
  322.    
  323.    jvm_branch_if_false: INTEGER is
  324.      -- Gives the `program_counter' to be resolved.
  325.       require
  326.      result_type.is_boolean
  327.       deferred
  328.       end;
  329.  
  330.    jvm_branch_if_true: INTEGER is
  331.      -- Gives the `program_counter' to be resolved.
  332.       require
  333.      result_type.is_boolean
  334.       deferred
  335.       end;
  336.    
  337.    jvm_assign is
  338.      -- Basic assignment using value on top of stack.
  339.       require
  340.      is_writable
  341.       deferred
  342.       end;
  343.  
  344. feature {NONE}
  345.  
  346.    frozen jvm_standard_branch_if_false: INTEGER is
  347.      -- Gives the `program_counter' to be resolved.
  348.       require
  349.      result_type.is_boolean
  350.       do
  351.      compile_to_jvm;
  352.      Result := code_attribute.opcode_ifeq;
  353.       end;
  354.    
  355.    frozen jvm_standard_branch_if_true: INTEGER is
  356.      -- Gives the `program_counter' to be resolved.
  357.       require
  358.      result_type.is_boolean
  359.       do
  360.      compile_to_jvm;
  361.      Result := code_attribute.opcode_ifne
  362.       end;
  363.    
  364. feature
  365.  
  366.    to_integer: INTEGER is
  367.       do
  368.      error(start_position,fz_iinaiv);
  369.       end;
  370.  
  371. feature -- Pretty printing :
  372.    
  373.    pretty_print is
  374.      -- Start the `pretty_print' process.
  375.       require
  376.      fmt.indent_level >= 1;
  377.       deferred
  378.       ensure
  379.      fmt.indent_level = old fmt.indent_level;
  380.       end;
  381.    
  382.    print_as_target is
  383.      -- Print the expression viewed as a target plus the 
  384.      -- corresponding dot when it is necessary.
  385.       deferred
  386.       end;
  387.    
  388.    bracketed_pretty_print is
  389.      -- Add bracket only when it is necessary.
  390.       deferred
  391.       end;
  392.       
  393. feature -- For `short' :
  394.    
  395.    short is
  396.       deferred
  397.       end;
  398.  
  399.    short_target is
  400.      -- A target with the following dot if needed.
  401.       deferred
  402.       end;
  403.  
  404.    frozen bracketed_short is
  405.       do
  406.      short_print.hook_or("open_b","(");
  407.      short;
  408.      short_print.hook_or("close_b",")");
  409.       end;
  410.    
  411. end -- EXPRESSION
  412.